package yangbajing.common

trait EnumTrait {
  this: Enumeration =>

  lazy val tupleValues = values.map(v => v.id.toString -> v.toString).toList

  lazy val objTupleValues = values.map(v => v -> v.toString).toList

  lazy val idTupleValues = values.map(v => v.id -> v.toString).toList

  def parse(i: Int): this.type#Value = apply(i)

  def parse(s: String): this.type#Value = withName(s)

  def option(v: Any): Option[this.type#Value] =
    try
      Some(v match {
        case i: Int => parse(i)
        case s: String => parse(s)
      })
    catch {
      case _: Exception =>
        None
    }

}
